<template>
  <div class="search">
    <!-- header -->
    <van-nav-bar
      title="查降权"
      left-text="返回"
      class="search-nav"
      ref="header"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-search v-model="aliim" shape="round" placeholder="请输入旺旺号" />
    <van-button type="primary" round block color="#e4393c" @click="onSearch">查询</van-button>
    <ul class="search—main">
      <li>
        <span>买家: {{ aliimSim }}****</span>
        <span>实名认证: {{ nameconform_word }} {{ vip_level }} {{ vip_info }}</span>
      </li>
      <li>
        <span>买家信誉: {{ buyerCre }}</span>
        <span>注册日期: {{ created }}</span>
      </li>
      <li>
        <span>商家信誉: {{ sellerCredit }}</span>
        <span>淘龄: {{ registDay }}</span>
      </li>
      <li>
        <span>性别: {{ sex }}</span>
        <span>买家总周平均: {{ buyerAvg }}</span>
      </li>
      <li>
        <span>好评率: {{ received_rate }}</span>
      </li>
      <li>
        <span>查询时间: {{ queryTime }}</span>
      </li>
    </ul>
    <h3>用户被打标情况</h3>
    <ul class="search-user">
      <li>
        <span>兔子</span>
        <span>{{ type1 }}</span>
      </li>
      <li>
        <span>蜜獾</span>
        <span>{{ type2 }}</span>
      </li>
      <li>
        <span>狐狸</span>
        <span>{{ type3 }}</span>
      </li>
      <li>
        <span>鳄鱼</span>
        <span>{{ type4 }}</span>
      </li>
      <li>
        <span>野狗</span>
        <span>{{ type5 }}</span>
      </li>
      <li>
        <span>老鼠</span>
        <span>{{ type6 }}</span>
      </li>
      <li>
        <span>降权</span>
        <span>{{ downNum }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
import dayjs from "dayjs";
export default {
  name: "Search",
  data() {
    return {
      aliim: "",
      aliimSim: "",
      nameconform_word: "",
      vip_level: "",
      vip_info: "",
      buyerCre: "",
      created: "",
      registDay: "",
      sellerCredit: "",
      sex: "",
      buyerAvg: "",
      received_rate: "",
      queryTime: "",
      type1: 0,
      type2: 0,
      type3: 0,
      type4: 0,
      type5: 0,
      type6: 0,
      downNum: 0
    };
  },
  created() {
    // this.onLogin();
  },
  mounted() {
    const _this = this;
    this.$nextTick(() => {
      var statusBar = window.api.require("statusBar");
      //异步返回结果：
      statusBar.getStatusBarHeight(function(ret) {
        _this.$refs.header.$el.style.height = ret.statusHeight + 44 + "px";
        _this.$refs.header.$el.style.paddingTop = ret.statusHeight + "px";
        _this.$refs.header.$el.getElementsByClassName(
          "van-nav-bar__left"
        )[0].style.top = ret.statusHeight + "px";
      });
    });
  },
  methods: {
    // 返回
    onClickLeft() {
      window.api.closeWin();
    },
    // 登录照妖镜
    onLogin() {
      const _this = this;
      window.api.ajax(
        {
          url: "http://139.159.141.200/app/superscanPH/loginPH.jsp",
          method: "post",
          returnAll: false,
          data: {
            values: {
              m: "login",
              username: "18857322772",
              password: "123456789",
              parcame: "ajax"
            }
          }
        },
        function(ret, err) {
          if (ret) {
            if (ret.result !== "lsu") {
              _this.$toast(ret.msg);
            } else {
              _this.onGetContent();
            }
          } else {
            _this.$toast(err.msg);
          }
        }
      );
    },
    // 搜索
    onSearch() {
      if (this.aliim === "") {
        this.$toast("请输入旺旺号");
      } else {
        if (this.$storage.has("time")) {
          if (dayjs().format("YYYY-MM-DD") == this.$storage.get("time")) {
            this.$toast("一天之内只允许查询一次");
          } else {
            this.onLogin();
          }
        } else {
          this.onLogin();
        }
      }
    },
    // 获取打标情况
    onGetContent() {
      const _this = this;
      window.api.showProgress({
        title: "获取中...",
        text: "先喝杯茶...",
        modal: false
      });
      window.api.ajax(
        {
          url: "http://139.159.141.200/app/superscanPH/opQuery.jsp",
          method: "post",
          returnAll: false,
          data: {
            values: {
              m: "bdwx",
              q: "qu"
            }
          }
        },
        function() {
          window.api.ajax(
            {
              url: "http://139.159.141.200/app/superscanPH/opQuery.jsp",
              method: "post",
              returnAll: false,
              data: {
                values: {
                  m: "queryAliim",
                  aliim: _this.aliim
                }
              }
            },
            function(res) {
              window.api.hideProgress();
              if (res.result === "正常") {
                _this.$storage.set("time", dayjs().format("YYYY-MM-DD"));
                _this.aliimSim = res.aliimSim;
                _this.nameconform_word = res.nameconform_word;
                _this.vip_level = res.vip_level;
                _this.vip_info = res.vip_info;
                _this.buyerCre = res.buyerCre;
                _this.created = res.created;
                _this.registDay = res.registDay;
                _this.sellerCredit = res.sellerCredit;
                _this.sex = res.sex;
                _this.buyerAvg = res.buyerAvg;
                _this.received_rate = res.received_rate;
                _this.queryTime = res.queryTime;
                _this.type1 = res.type1;
                _this.type2 = res.type2;
                _this.type3 = res.type3;
                _this.type4 = res.type4;
                _this.type5 = res.type5;
                _this.type6 = res.type6;
                _this.downNum = res.downNum;
              } else {
                _this.$toast(res.result);
              }
            }
          );
        }
      );
    }
  }
};
</script>

<style lang="scss">
.search {
  width: 100%;
  @include flex(
    $direction: column,
    $justifyContent: flex-start,
    $flexWrap: nowrap
  );
  .van-search {
    width: 100%;
    .van-search__content {
      height: 44px;
      line-height: 44px;
      .van-cell {
        @include flex();
      }
    }
  }
  .van-button--block {
    width: 345px;
  }
  .search—main {
    width: 345px;
    margin: 30px 0;
    padding: 15px;
    background: rgb(240, 240, 240);
    li {
      @include flex();
      line-height: 34px;
      span {
        flex: 1;
        font-size: 12px;
      }
    }
  }
  h3 {
    margin-bottom: 30px;
  }
  .search-user {
    width: 345px;
    @include flex();
    li {
      @include flex($direction: column);
      span {
        font-size: 12px;
        &:first-child {
          padding: 5px 8px;
          background: rgb(240, 240, 240);
          border-radius: 12px;
          margin-bottom: 10px;
        }
      }
    }
  }
}
</style>
